package io.adrainty.bolee.insurance.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import io.adrainty.bolee.framework.commons.basic.ResponseCode;
import io.adrainty.bolee.framework.commons.exception.AppException;
import io.adrainty.bolee.insurance.models.entity.SafeguardEntity;
import io.adrainty.bolee.insurance.repository.ISafeguardRepository;
import io.adrainty.bolee.insurance.service.ISafeguardService;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author AdRainty
 * @version V1.0.0
 * @since 2025/8/10 下午9:46
 */

@Service
public class SafeguardServiceImpl implements ISafeguardService {

    @Resource
    private ISafeguardRepository safeguardRepository;

    @Override
    public IPage<SafeguardEntity> findSafeguardPage(Integer pageNum, Integer pageSize, SafeguardEntity searchDTO) {
        return safeguardRepository.findSafeguardPage(pageNum, pageSize, searchDTO);
    }

    @Override
    public List<SafeguardEntity> findSafeguardList(SafeguardEntity entity) {
        return safeguardRepository.findSafeguardList(entity);
    }

    @Override
    public SafeguardEntity createSafeguard(SafeguardEntity entity) {
        if (!safeguardRepository.createSafeguard(entity)) {
            throw new AppException(ResponseCode.SAFEGUARD_CREATE_ERROR);
        }
        return entity;
    }

    @Override
    public Boolean updateSafeguard(SafeguardEntity entity) {
        if (entity.getId() == null) {
            throw new AppException(ResponseCode.ILLEGAL_PARAMETER);
        }
        return safeguardRepository.updateSafeguard(entity);
    }

    @Override
    public Boolean deleteSafeguard(List<String> deleteIdList) {
        return safeguardRepository.deleteSafeguard(deleteIdList);
    }


}
